package adventure.commands;

/**
 *
 * @author Michael Hanns
 *
 */
public class Util {

    /**
     *
     * @param Command and arguments
     * @return Arguments with spaces between
     */
    public static String consolidateArguments(String[] args) {
        if (args.length > 1) {
            String arg = args[1];
            for (int c = 2; c < args.length; c++) {
                arg += " " + args[c];
            }
            return arg;
        }
        return "";
    }

    public static boolean isInteger(String intStr) {
        try {
            Integer.parseInt(intStr);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    public static boolean isDirection(String command) {
        if (command.length() > 0) {
            command = command.toUpperCase();
            if ("NORTH".startsWith(command)) {
                return true;
            } else if ("EAST".startsWith(command)) {
                return true;
            } else if ("SOUTH".startsWith(command)) {
                return true;
            } else if ("WEST".startsWith(command)) {
                return true;
            } else if ("UP".startsWith(command)) {
                return true;
            } else if ("DOWN".startsWith(command)) {
                return true;
            }
        }

        return false;
    }

    public static String fillDir(char dir) {
        dir = Character.toUpperCase(dir);
        String direction = "error";
        switch (dir) {
            case 'E':
                direction = "eastern";
                break;
            case 'S':
                direction = "southern";
                break;
            case 'W':
                direction = "western";
                break;
            case 'N':
                direction = "northern";
                break;
            case 'U':
                direction = "upper";
                break;
            case 'D':
                direction = "lower";
                break;
        }
        return direction;
    }
    
    public static String oppositeDirection(char dir) {
        dir = Character.toUpperCase(dir);
        String direction = "error";
        switch (dir) {
            case 'E':
                direction = "the west";
                break;
            case 'S':
                direction = "the south";
                break;
            case 'W':
                direction = "the east";
                break;
            case 'N':
                direction = "the north";
                break;
            case 'U':
                direction = "below";
                break;
            case 'D':
                direction = "above";
                break;
        }
        return direction;
    }
}
